package modelLayer;

/**
 * This class is a modelLayer class of the MSAS system. It holds
 * information on a single block. True to our domain model, the block
 * class has field visibility to TeachingBlock. The Block class is itself
 * contained in Schedule.
 * 
 * @author Danny M�lgaard, Anna Kelemen, Jakob Korsgaard
 * 		   
 * @version 1.3.1
 * 					1.3.1: 		Added more extensive documentation. Verified that
 * 								information contained in the Design Class Diagram,
 * 								is in accordance with the information contained in this
 * 								class.
 * 					1.3.2:		toString() adjusted
 */
public class Block {

	private int id;
	private int number;
	private TeachingBlock tb;
	
	
	/**
	 * Instantiating a Block object, taking no parameters, altering no variables.
	 */
	public Block() {	
	}
	
	/**
	 * Instantiating a Block object, taking the following parameters:
	 * 
	 * @param	number	int		the location of the block in the
	 * 							schedule.
	 */
	public Block(int number) {
		
		this.setBlockNumber(number);
		
	}

	/**
	 * Instantiating a Block object, taking the following parameters:
	 * 
	 * @param	id		int		the id of the block, as allocated in the database.
	 * @param	number	int		the location of the block in the schedule.
	 */
	public Block(int id, int number){
		
		this.setId(id);
		this.setBlockNumber(number);
		
	}
	
	/**
	 * Assigns a parameter to the tb field, referencing a TeachingBlock object.
	 * 
	 * @param 	tb		TeachingBlock	the TeachingBlock object to be referenced by
	 * 									the block.			
	 */
	public void setTeachingBlock(TeachingBlock tb) {
				
		this.tb = tb;
		
	}
	
	/**
	 * Assigns a parameter to the number field, defining the blocks place in the schedule.
	 * 
	 * @param 	number		int		the position in the schedule.					
	 */
	public void setBlockNumber(int number) {

		this.number = number;

	}
	
	/**
	 * Assigns a parameter to the number field, assigning the, by the database, allocated id.
	 * 
	 * @param 	id			int		the identification of the block in the database.					
	 */
	public void setId(int id) {
		
		this.id = id;

	}
	
	/**
	 * Returns the TeachingBlock object associated with the Block object.
	 * 
	 * @return 	tb			TeachingBlock	the TeachingBlock object referenced by the Block object
	 */
	public TeachingBlock getTeachingBlock() {

		return this.tb;

	}

	/**
	 * Returns the position in the schedule for the respective Block object.
	 * 
	 * @return 	number		int		the block's position in the schedule.
	 */
	public int getBlockNumber() {

		return this.number;

	}

	/**
	 * Returns the blocks id, as allocated in the database.
	 * 
	 * @return 	id			int		the block's id as allocated in the database.
	 */
	public int getId() {
		
		return this.id;

	}

	/**
	 * Overrides the object's default toString() method. Returns the object as a String
	 * literal to the caller.
	 * 
	 * return				String	the Block object represented as a String object.
	 */
	@Override
	public String toString() {
		
//		if (this.tb == null) {
//			return "Block Number " + this.number + ": " + "null";
//		}
//		else {
//			return "Block Number " + this.number + ": " + tb.getName() + "\n";
//		}
		if (this.tb == null) {
			return "";
		}
		else {
			return this.tb.getName();
		}

	}

	/**
	 * Implements a check, to verify if an object is the same
	 * as this object. Uses object identification number to
	 * verify.
	 * 
	 * @param	o		Object	any object type.
	 * @return	true			if: 
	 * 							object is not null, and
	 * 							object is of type Block, and
	 * 							object id field matches this objects id field.
	 * @return	false			if:
	 * 							object is null, or
	 * 							object is not an instance of Block, or
	 * 							object id field doesn't match this objects id field.
	 */
	@Override
	public boolean equals(Object o) {
		
		if (o != null && (o instanceof Block)){
			Block b = (Block) o;
			if (this.getBlockNumber() == b.getBlockNumber()) {
				return true;
			}
		}

		return false;

	}

}
